<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn1">向主进程发送数据</button>
    <!-- 渲染进程
            默认情况下，渲染进程是无法直接获取主进程中的全局数据
    -->
    <script>
        // console.log(username)    username is not defined

        const {remote,ipcRenderer} = require('electron')
        console.log(remote.getGlobal('username'))  // 即可访问主线程中的username值：kanglang

        document.getElementById('btn1').addEventListener('click',()=>{
            ipcRenderer.send('link-mainProcess','Request to connect to the main process') // 向主进程发送一个事件link-mainProcess，并携带信息Request to connect to the main process
        })

        ipcRenderer.on('reply-renderProcess',(event,arg)=>{   // 接收主线程返回的数据
            console.log(arg)  
        })

        console.log(ipcRenderer.sendSync('sendMes'))  // 接收主线程发过来的数据
    </script>
</body>
</html>